from django.db import models
from apps.users.models import BaseModel
from apps.organizations.models import Teacher

DEGREE_CHOICES = (("CJ", "初级"), ("ZJ", "中级"), ("GJ", "高级"))


# Create your models here.
# 实体 ： 1课程 2章节 3讲师 4 资料
class Course(BaseModel):
    teacher = models.ForeignKey(Teacher, verbose_name="讲师", on_delete=models.CASCADE)
    name = models.CharField(verbose_name="名称", max_length=80)
    desc = models.CharField(verbose_name="详情", max_length=500)
    learn_times = models.IntegerField(verbose_name="学习时长(分钟)", default=0)
    degree = models.CharField(verbose_name="难度", choices=DEGREE_CHOICES, max_length=2)
    students = models.IntegerField(verbose_name="学习人数", default=0)
    fav_nums = models.IntegerField(verbose_name="收藏人数", default=0)
    click_nums = models.IntegerField(verbose_name="点击人数", default=0)
    category = models.CharField(verbose_name="课程类型", max_length=20, default=u"ui设计师")
    tag = models.CharField(verbose_name="标签", max_length=20, default="")
    read_me = models.CharField(verbose_name="课程须知", max_length=300, default="")
    teacher_tell = models.CharField(verbose_name="老师告诉你", max_length=300, default="")
    detail = models.TextField(verbose_name="课程详情")
    image = models.ImageField(verbose_name="封面图", upload_to="course/%Y%m", max_length=128)

    class Meta:
        verbose_name = "课程"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name


class Lesson(BaseModel):
    course = models.ForeignKey(Course, on_delete=models.CASCADE)
    name = models.CharField(verbose_name="名称", max_length=80)
    learn_times = models.IntegerField(verbose_name="学习时长(分钟)", default=0)

    class Meta:
        verbose_name = "章节"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name


class Video(BaseModel):
    lesson = models.ForeignKey(Lesson, on_delete=models.CASCADE)
    name = models.CharField(verbose_name="名称", max_length=120)
    learn_times = models.IntegerField(verbose_name="学习时长(分钟)", default=0)
    url = models.FileField(verbose_name="访问地址", upload_to="course/video/%Y%m", max_length=200)

    class Meta:
        verbose_name = "视频"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name


class CourseResourse(BaseModel):
    course = models.ForeignKey(Course, on_delete=models.CASCADE, verbose_name="课程")
    name = models.CharField(verbose_name="名称", max_length=40)
    file = models.FileField(verbose_name="下载地址", max_length=200, upload_to="course/sourse/%Y%m")

    class Meta:
        verbose_name = "课程资源"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name
